package com.xiaoliang.servlet;

import com.xiaoliang.entry.Product;
import com.xiaoliang.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author XIAOLIANG
 * @ClassName UpdateProduct.java
 * @Description TODO
 * @createTime 2021年02月26日 10:46:00
 */
//@WebServlet("/product/getOneProduct")
public class GetOneProduct extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		String id = req.getParameter("id");
		if (id!=null){
			id = id.trim();
		}
		ProductServiceImpl productService = new ProductServiceImpl();

		assert id != null;
		Product product = productService.selectOneById(Integer.parseInt(id));

		HttpSession session = req.getSession();

		session.setAttribute("product",product);
		session.setAttribute("type",1);
		session.setAttribute("requestAddr","update");

		resp.sendRedirect(req.getContextPath()+"/product/addOrUpdate.jsp");


	}
}
